#pragma once
//============================================================================
// Copyright (C) 2013 Brett R. Jones
//
// Issued to public domain 2013
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================
#include "VxDefs.h"
#include <string>

#define DEFAULT_ONLINE_LISTEN_PORT		45654
#define DEFAULT_GUEST_UDP_PORT			45653

extern U32			g_u32SysTimeSec;		// unix time stamp.. seconds since January 1, 1970 local time
extern S32			g_s32GmtTimeOffs;		// offset in seconds to turn local time to gmt time
extern U32			g_u32ElapsedTimeMs;		// elapsed time ( app alive time ) milliseconds
extern S64			g_s64SysTimeMs;			// system time in milliseconds local time
extern S64			g_s64StartupTimeMs;		// unix time in milliseconds of first update ( application start )

//============================================================================
//=== startup/shutdown ===//
//============================================================================
//! set application is shutting down
void			VxSetAppIsShuttingDown( bool bIsShuttingDown );
//! return true if application is shutting down
bool			VxIsAppShuttingDown( void );

//! set application name
void			VxSetApplicationName( const char * pAppName );
//! get application name
const char *	VxGetApplicationName( void );

//============================================================================
//=== time ===//
//============================================================================
//! Update system time
void			VxUpdateSystemTime( void );
//! Local to GmTime
inline U32		LocalToUtcTime( U32 u32LocalTime )	{ return (U32)((int)u32LocalTime + g_s32GmtTimeOffs); }
//! Local to GmTime
inline S64		LocalToUtcTime( S64 s64LocalTimeMs )	{ return (s64LocalTimeMs + ((S64)g_s32GmtTimeOffs * 1000)); }
//! GmTime to Local Time
inline U32		UtcTimeToLocal( U32 u32GmTime )		{ return (U32)((int)u32GmTime - g_s32GmtTimeOffs); };
//! GmTime to Local Time
inline S64		UtcTimeToLocal( S64 s64GmTimeMs )	{ return (s64GmTimeMs - (S64)g_s32GmtTimeOffs * 1000); };

inline U32		VxGetLocalTime( void )				{ return g_u32SysTimeSec;}
inline U32		VxGetUtcTime( void )				{ return LocalToUtcTime( g_u32SysTimeSec );}
inline S64		VxGetLocalTimeMs( void )			{ return g_s64SysTimeMs;}
inline S64		VxGetUtcTimeMs( void )				{ return LocalToUtcTime( g_u32SysTimeSec );}

//============================================================================
//=== miscellaneous ===//
//============================================================================
//! default name of rogue connections network
const char *	VxGetRogueNetworkName();
void			VxSetRogueNetworkName( const char * pNetName );

//! set true if loop back is allowed ( default is false )
void			VxSetNetworkLoopbackAllowed( bool bIsLoopbackAllowed );
//! return true if loop back is allowed
bool			VxIsNetworkLoopbackAllowed( void );

//! return default tcp/udp port for rogue connections
U16				VxGetRogueConnectionsDefaultTcpPort();
//! return default udp port for rogue connections
U16				VxGetRogueConnectionsDefaultUdpPort();

//============================================================================
//=== directories ===//
//============================================================================
//! get root directory this app has data in
std::string&	VxGetAppRootDir( void );
//! set root directory this app has data in
void			VxSetAppRootDir( std::string& strDir );
//! get root directory this app writes data to
std::string&	VxGetAppDataDir( void );
//! set root directory this app writes data to
void			VxSetAppDataDir( std::string& strDir );


void			VxSetUdpEnable( bool enableUpnp );
bool			VxIsUdpEnabled( void );
void			VxSetDebugEnable( bool enableDebug );
bool			VxIsDebugEnabled( void );

U16				VxGetAppVersion( void );
void			VxSetIsPaidApp( bool isPaidApp );
bool			VxIsPaidApp( void );


